/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aybolit.core.objects.dao.impl;

import aybolit.core.objects.dao.HealthAnalysysDao;
import aybolit.core.objects.model.HealingAnalyzes;
import java.io.Serializable;
import java.util.List;
import javax.annotation.Resource;
import org.hibernate.SessionFactory;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author Masumov Emin
 */
@Transactional
public class HealthAnalysysDaoImp implements HealthAnalysysDao, Serializable {

    SessionFactory sessionFactory;

    @Transactional
    @Override
    public List<HealingAnalyzes> findHealingAnalyzesByPacientId(String id) {
        return sessionFactory.getCurrentSession().getNamedQuery("HealingAnalyzes.findHealingAnalyzesByPacientId").setParameter("h_id", Integer.parseInt(id)).list();
    }

    @Resource(name = "sessionFactory")
    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    @Transactional
    @Override
    public HealingAnalyzes findHealingAnalyzByPacientId(String id) {
        return (HealingAnalyzes) sessionFactory.getCurrentSession().getNamedQuery("HealingAnalyzes.findHealingAnalyzByPacientId").setParameter("h_id", Integer.parseInt(id)).uniqueResult();

    }

    @Override
    public void saveHealingAnalyz(HealingAnalyzes healing) {
        sessionFactory.getCurrentSession().save(healing);
    }

    @Override
    public void saveOrUpdateHealingAnalyz(HealingAnalyzes healing) {
        sessionFactory.getCurrentSession().saveOrUpdate(healing);
    }

    @Override
    public HealingAnalyzes findHealingAnalyzById(String id) {
        return (HealingAnalyzes) sessionFactory.getCurrentSession().getNamedQuery("HealingAnalyzes.findHealingAnalyzById").setParameter("h_id", Integer.parseInt(id)).uniqueResult();
    }
}
